<template>
  <a-modal
    v-model="show"
    :title="isEdit ? '修改审批流' : '新增审批流'"
    :maskClosable="false"
    @cancel="onCancel()"
  >
    <a-form-model
      :label-col="{ span: 6 }"
      :wrapper-col="{ span: 14 }"
      :model="info"
      :rules="infoRules"
      ref="ruleForm"
    >
      <a-form-model-item label="审批流名称" required prop="ApprovalProcessName">
        <a-input v-model="info.ApprovalProcessName" />
      </a-form-model-item>
      <a-form-model-item label="审批流描述">
        <a-textarea style="resize: none" v-model="info.ApprovalProcessDesc" />
      </a-form-model-item>
    </a-form-model>
    <template slot="footer">
      <a-button key="back" @click="onCancel()">取消</a-button>
      <a-button key="submit" type="primary" @click="onOk">提交</a-button>
    </template>
  </a-modal>
</template>
 
<script>
import {
  insApprovalProcess,
  updApprovalProcess,
} from "@/api/JobRecordApproval";
export default {
  props: ["show", "isEdit", "info"],
  data() {
    return {
      infoRules: {
        ApprovalProcessName: [
          { required: true, message: "请填写审批名称", trigger: "blur" },
        ],
      }, //校验
    };
  },
  methods: {
    onOk() {
      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          if (this.isEdit) {
            let res = await updApprovalProcess([this.info]);
            this.$message.success(res.Message);
            this.$emit("upDataList");
            this.onCancel();
          } else {
            let res = await insApprovalProcess([this.info]);
            this.$message.success(res.Message);
            this.$emit("upDataList");
            this.onCancel();
          }
        } else {
          this.$message.error("请填写完必填信息");
        }
      });
    },
    onCancel() {
      this.$emit("update:show", false);
      this.$refs.ruleForm.resetFields();
    },
  },
};
</script>
 
<style lang = "less" scoped>
</style>